package com.moonbird.springboot.controller;

import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.moonbird.springboot.DTO.Result;
import com.moonbird.springboot.Utils.AudioTranscriptionUtils;
import com.moonbird.springboot.pojo.VideoRequest;
import com.moonbird.springboot.service.PptService;
import com.moonbird.springboot.service.QwenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.json.JSONObject;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.StandardCopyOption;

@RestController
@RequestMapping("/api/qwen")
public class QwenController {

    @Autowired
    private QwenService qwenService;
    //qwen-turbo
    @PostMapping("/turboResponse")
    public Result<String> getQwenTurboResponse(@RequestBody String userMessage) throws ApiException, NoApiKeyException, InputRequiredException {
        return qwenService.chat(userMessage);
    }

    //生成音频，返回的是一个音频网络路径
    @PostMapping("/toAudio")
    public Result<String> getQwenAudio(@RequestBody String AiudioMessage) {
        return qwenService.toAudio(AiudioMessage);
    }

    //生成图片
    @PostMapping("/createImage")
    public Result<String> createImage(@RequestBody String description) {
        // 解析 JSON 字符串
        JSONObject jsonObject = new JSONObject(description);
        // 获取 "description" 字段的值
        description = jsonObject.getString("description");
        System.out.println("============================================--------");
        System.out.println("text:" + description);
        System.out.println("============================================--------");
        return qwenService.createImage(description);
    }

    //音频转文字
    @PostMapping("/transcribeAudio")
    public Result<String> transcribeAudio(@RequestParam("file") MultipartFile file) throws IOException {
        return qwenService.transcribeAudio(file);


    }
}